import {defineStore} from "pinia";
import {SET_AUTH_CODE, SET_LOGIN_STATE, SET_USER_INFO} from "./mutationTypes";

export const userConfigStore = defineStore({
    id: 'userConfig',
    state: () => ({
        // 用户信息
        userInfo: {},
        // 用户权限
        authCode: [],
        isLogin: false,
    }),
    getters: {
        getUserPhoto: (state: any) => {
            if (state.isLogin) {
                if (state.userInfo.photoUrl) {
                    return state.userInfo.photoUrl;
                } else {
                    return "https://fengqi-bucket.oss-cn-chengdu.aliyuncs.com/blog/my/avatar.png";
                }
            } else {
                return "https://fengqi-bucket.oss-cn-chengdu.aliyuncs.com/blog/my/avatar.png";
            }
        }
    },
    actions: {
        [SET_USER_INFO](userInfo: any) {
            this.userInfo = userInfo;
        },
        [SET_LOGIN_STATE](isLogin: boolean) {
            this.isLogin = isLogin;
        },
        [SET_AUTH_CODE](authCode: any) {
            this.authCode = authCode;
        }
    }
})
